﻿'Public Enumerations and Subs for GUI handling of the Pack Controls
'==================================================================
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Module modGlobalGUI
  'Enumeration for control appearance
  Public Enum MediaBoxGraphicStyle As Integer
    Solid = 0
    Gradient = 1
  End Enum

  'Enumeration for control border style
  Public Enum MediaBoxBorderStyle As Integer
    None = 0
    Flat = 1      'Only in flat mode the border style can accept different colors
    SunkenSoft = 2
    SunkenHard = 3
    RaisedSoft = 4
    RaisedHard = 5
    Etched = 6
    Border = 7
  End Enum

  'Enumeration for control orientation
  Public Enum MediaBoxOrientation As Integer
    Horizontal = 0
    Vertical = 1
  End Enum

  Public Sub PaintBorder(ByVal g As Graphics, ByVal rc As Rectangle, _
                         ByVal clr As Color, ByVal st As MediaBoxBorderStyle)
    'Sub to draw a border around a specific area
    '
    'Sides
    Dim ptLeft() As Point = {New Point(rc.Left, rc.Top + rc.Height - 1), New Point(rc.Left, rc.Top)}
    Dim ptLeftIn() As Point = {New Point(rc.Left + 1, rc.Top + rc.Height - 2), _
                               New Point(rc.Left + 1, rc.Top + 1)}
    Dim ptTop() As Point = {New Point(rc.Left, rc.Top), New Point(rc.Left + rc.Width, rc.Top)}
    Dim ptTopIn() As Point = {New Point(rc.Left + 1, rc.Top + 1), _
                              New Point(rc.Left + rc.Width - 2, rc.Top + 1)}
    Dim ptRight() As Point = {New Point(rc.Left + rc.Width - 1, rc.Top), _
                              New Point(rc.Left + rc.Width - 1, rc.Top + rc.Height)}
    Dim ptRightIn() As Point = {New Point(rc.Left + rc.Width - 2, rc.Top + 1), _
                                New Point(rc.Left + rc.Width - 2, rc.Top + rc.Height - 2)}
    Dim ptBottom() As Point = {New Point(rc.Left, rc.Top + rc.Height - 1), _
                               New Point(rc.Left + rc.Width - 1, rc.Top + rc.Height - 1)}
    Dim ptBottomIn() As Point = {New Point(rc.Left + 1, rc.Top + rc.Height - 2), _
                               New Point(rc.Left + rc.Width - 2, rc.Top + rc.Height - 2)}
    'Pens
    Dim pColor As New Pen(clr)
    Dim pControl As New Pen(Color.FromName("ButtonFace"))
    Dim pShadow As New Pen(Color.FromName("ButtonShadow"))
    Dim pLight As New Pen(Color.FromName("ButtonHighLight"))
    Dim pDark As New Pen(Color.FromName("ControlDarkDark"))
    'Painting
    Select Case st
      Case MediaBoxBorderStyle.Flat 'Flat border
        g.DrawLines(pColor, ptLeft)
        g.DrawLines(pColor, ptTop)
        g.DrawLines(pColor, ptRight)
        g.DrawLines(pColor, ptBottom)
      Case MediaBoxBorderStyle.RaisedSoft 'Softly raised border
        g.DrawLines(pLight, ptLeft)
        g.DrawLines(pLight, ptTop)
        g.DrawLines(pShadow, ptRight)
        g.DrawLines(pShadow, ptBottom)
      Case MediaBoxBorderStyle.SunkenSoft 'Softly sunken border
        g.DrawLines(pShadow, ptLeft)
        g.DrawLines(pShadow, ptTop)
        g.DrawLines(pLight, ptRight)
        g.DrawLines(pLight, ptBottom)
      Case MediaBoxBorderStyle.RaisedHard 'Hardly raised border
        g.DrawLines(pLight, ptLeft) : g.DrawLines(pControl, ptLeftIn)
        g.DrawLines(pLight, ptTop) : g.DrawLines(pControl, ptTopIn)
        g.DrawLines(pDark, ptRight) : g.DrawLines(pShadow, ptRightIn)
        g.DrawLines(pDark, ptBottom) : g.DrawLines(pShadow, ptBottomIn)
      Case MediaBoxBorderStyle.SunkenHard 'Hardly sunken border
        g.DrawLines(pDark, ptLeft) : g.DrawLines(pShadow, ptLeftIn)
        g.DrawLines(pDark, ptTop) : g.DrawLines(pShadow, ptTopIn)
        g.DrawLines(pLight, ptRight) : g.DrawLines(pControl, ptRightIn)
        g.DrawLines(pLight, ptBottom) : g.DrawLines(pControl, ptBottomIn)
      Case MediaBoxBorderStyle.Etched 'Etched border
        g.DrawLines(pShadow, ptLeft) : g.DrawLines(pLight, ptLeftIn)
        g.DrawLines(pShadow, ptTop) : g.DrawLines(pLight, ptTopIn)
        g.DrawLines(pLight, ptRight) : g.DrawLines(pShadow, ptRightIn)
        g.DrawLines(pLight, ptBottom) : g.DrawLines(pShadow, ptBottomIn)
      Case MediaBoxBorderStyle.Border 'Bordered border
        g.DrawLines(pShadow, ptLeft) : g.DrawLines(pLight, ptLeftIn)
        g.DrawLines(pShadow, ptTop) : g.DrawLines(pLight, ptTopIn)
        g.DrawLines(pShadow, ptRight) : g.DrawLines(pLight, ptRightIn)
        g.DrawLines(pShadow, ptBottom) : g.DrawLines(pLight, ptBottomIn)
    End Select
    'Disposing
    pColor.Dispose()
    pControl.Dispose()
    pShadow.Dispose()
    pLight.Dispose()
    pDark.Dispose()
  End Sub
End Module